// pages/my/vip/vipCard_detail/index.js
const app=getApp();
const getVipDetail=require("../../../controllers/ControllerVip").controller.getVipDetail;
const receive=require("../../../controllers/ControllerVip").controller.receive;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    globalStype:'',
    value:{
      accountVipId:'',
      shopId:''
    },
    detail_list:[],
    dialogShow: false,
    buttons: [{text: '取消'}, {text: '确定'}],
    vipGoodsId:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({globalStype:app.globalData.globalStype})
    let id=options.id;
    this.setData({
      'value.accountVipId':id
    })
    if(options.shopId){
      this.setData({
        'value.shopId':options.shopId
      })
    }else{
      this.setData({
        'value.shopId':app.globalData.shopId
      })
    }
    this.getCardDetail();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //获取会员卡详情
  getCardDetail(){
    // this.setData({
    //   'value.shopId':app.globalData.shopId
    // })
    getVipDetail(this.data.value).then(res=>{
      this.setData({
        detail_list:res.data
      })
      console.log(this.data.detail_list)
    })
  },

  //核销（领取商品）
  receiveGoods(options){
    let shopId=this.data.value.shopId;
    let vipGoodsId=this.data.vipGoodsId;
    receive({shopId:shopId,vipGoodsId:vipGoodsId}).then(res=>{
      this.getCardDetail();
      wx.showToast({
        title: '成功领取',
        duration:1500
      })
    })
  },
  openConfirm: function (options) {
    let vipGoodsId=options.currentTarget.dataset.id;
    this.setData({
      vipGoodsId:vipGoodsId
    })
    this.setData({
        dialogShow: true
    })
},
  tapDialogButton(e) {
    let index=e.detail.index;
    if(index==0){

    }else{
      this.receiveGoods()
    }
    this.setData({
        dialogShow: false,
    })
    console.log(e);
    console.log("1111")
},
})